package at.tugraz.akm.forume.extras;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public abstract class MySharedPreferences {

	final static String PREFS_NAME = "forume";
	public final static String USERNAME = "username";
	public final static String PASSWORD = "password";
	public final static String USER_ID = "user_id";
	public final static String UNDEFINED = "undefined";

	public static void print(Context context){
		Log.e(USERNAME, getString(context, USERNAME));
		Log.e(PASSWORD, getString(context, PASSWORD));
		Log.e(USER_ID, getString(context, USER_ID));
	}
	
	public static void clear(Context context) {
		setString(context, USER_ID, UNDEFINED);
		setString(context, USERNAME, UNDEFINED);
		setString(context, PASSWORD, UNDEFINED);
	}

	public static String getString(Context context, String key) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		String value = settings.getString(key, UNDEFINED);
		return value;
	}

	public static boolean setString(Context context, String key, String value) {
		SharedPreferences settings = context
				.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(key, value);
		return editor.commit();
	}

}
